package main

import (
	"context"
	log "github.com/sirupsen/logrus"
	"oa-rest/common"
	"oa-rest/config"
)

func main() {
	config.InitEnv()
	common.InitMinioClient()
	// 删除所有已经存在的bucket
	ctx := context.Background()
	bucketList, err := common.MinioClient.Client.ListBuckets(ctx)
	if err != nil {
		log.Fatal(err)
		return
	}
	for _, info := range bucketList {
		err := common.MinioClient.DeleteBucket(info.Name)
		if err != nil {
			log.Fatal(err)
			return
		}
	}

	buckets := []string{
		"meeting",
		"sharefile",
		"documents",
		"culture",
		"incoming",
		"official-document",
		"signature",
		"task-attachments",
	}

	for _, bucket := range buckets {
		err = common.CreateBucket(bucket, true)
		if err != nil {
			log.Fatal(err)
			return
		}
		log.Infof("Create bucket: %s", bucket)
	}
}
